package com.example.xyr.myapplication.base

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

/**
 * Created by ylcf on 2018/9/6.
 */
abstract class BaseFragment : Fragment() {
    protected var mActivity: Activity? = null

    protected abstract fun initView(view: View, savedInstanceState: Bundle?)

    //获取布局文件ID
    protected abstract fun getLayoutId(): Int

    //获取宿主Activity
    protected fun getHoldingActivity(): Activity {
        return mActivity!!
    }

    override fun onAttach(context: Context?) {
        super.onAttach(context)
        this.mActivity = context as Activity
    }


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(getLayoutId(), container, false)
        var args = arguments
        initView(view, args)
        return view
    }
}